package com.dldata.devtools30.enumpak;


public interface EnumBase {

    public abstract  BaseEnumObj getValueObj();

    public static class BaseEnumObj{
        public int value;
        public String code;
        public String label;

        public BaseEnumObj(int value, String code, String label){
            this.value=value;
            this.code=code;
            this.label=label;
        }

        public static <T extends Enum> T getEnumByCode(Class<T> tClass,String code,T[] ts){

            for (int i = 0; i < ts.length; i++) {
                EnumBase enumBase = (EnumBase)ts[i];
                if(enumBase.getValueObj().code.equalsIgnoreCase(code)){
                    return ts[i];
                }
            }
            return null;
        }

        public static <T extends Enum> T getEnumByValue(Class<T>[] tClass,int value ,T[] ts ){
            for (int i = 0; i < ts.length; i++) {
                EnumBase enumBase = (EnumBase)ts[i];
                if(enumBase.getValueObj().value==(value)){
                    return ts[i];
                }
            }
            return null;
        }

        public static <T extends Enum> T getEnumByLabel(Class<T> tClass,String label,T[] ts){

            for (int i = 0; i < ts.length; i++) {
                EnumBase enumBase = (EnumBase)ts[i];
                if(enumBase.getValueObj().label.equals(label)){
                    return ts[i];
                }
            }
            return null;
        }
    }
}
